﻿using System;

namespace BizElements.Core
{
    /// <summary>Binds/maps properties of generated class to columns and relations.</summary>
    public interface IEntityPropertyBinder
    {
        /// <summary>Gets or sets bound entity.</summary>
        IEntity BoundEntity { get; set; }

        /// <summary>
        /// Resets the specified field to default value.
        /// Behaviour should be the same as using the SetField method with a null argument.
        /// </summary>		
        /// <param name="field">Field that is to be reset.</param>
        void ResetField(IDbColumn field);

        /// <summary>
        /// Sets the given value into specified field.
        /// </summary>
        /// <param name="field">Field.</param>
        /// <param name="value">Value. If null then the field is reset to default value.</param>
        void SetField(IDbColumn field, object value);

        /// <summary>
        /// Gets the value contained in the specified field.
        /// </summary>
        /// <param name="field">Field.</param>
        /// <returns>Value.</returns>
        object GetField(IDbColumn field);

        /// <summary>
        /// Checks whether the specified field contains a <b>null</b> reference or it hasn't been initialized.
        /// </summary>
        /// <param name="field">Field. Throws exception if an invalid field is given.</param>
        /// <returns><b>true</b> if the field contains <b>null</b> not initialized; <b>false</b> otherwise.</returns>
        bool IsNull(IDbColumn field);

        /// <summary>
        /// Sets the given value into the member that represents the parent entity defined by the foreign key.
        /// </summary>
        /// <param name="foreignKey">FK.</param>
        /// <param name="entity">Parent entity.</param>
        void SetParent(DbRelation foreignKey, IEntity entity);

        /// <summary>
        /// Gets the parent entity defined by the given foreign key.
        /// </summary>
        /// <param name="foreignKey">FK.</param>
        /// <returns>Parent entity. <b>Null</b> if the FK fields haven't been set or if the entity with the given key values doesn't exist.</returns>
        /// <remarks>If a class implements data-access logic, and if the entity hasn't yet been initialized but the 
        /// FK values are set then the method will automatically fetch it from the data source.</remarks>
        IEntity GetParent(DbRelation foreignKey);
    }
}
